******SET YOUR DIRECTORY to ...\replication



clear all
set more off

set matsize 2000

grstyle init
grstyle set plain
grstyle set color s2

use "finaldata\final_cc_data.dta", clear

set matsize  700
drop if fipsplace_00==.
xtset fipsplace_00 year

*Create instrument
g good_soil = (ph1_plc_wtm_wtm_0_r>=6.8 & ph1_plc_wtm_wtm_0_r<=7.7)
g bad_soil = (1- good_soil)

forval yy = 1961/2014 {
	g bad_soilXY`yy' = (year==`yy') * bad_soil
	label var bad_soilXY`yy' "High LB x `yy'"
}

*Create outcome
gen vc_pc=totnpcc_cc_offenses_vc*1000

*Cluster variables
egen cdivcodeyear=group(cdivcode year)

*Label variables
label var vc_pc "Violent crime CC"
label var bad_soil "High LB"
label var cdivcodeyear "Census Division Code x Year"

reghdfe vc_pc bad_soilXY*, a(fipsplace_00 year cdivcode#year)  cluster(cdivcodeyear)

mat treat = J(55,4,1)

mat treat[1,1] = 1960
mat treat[1,2] = 0
mat treat[1,3] = 0
mat treat[1,4] = 0

forval yy = 1961/2014 {
local pos = `yy' - 1959
mat treat[`pos',1] = `yy'
mat treat[`pos',2] = _b[bad_soilXY`yy']
mat treat[`pos',3] = _b[bad_soilXY`yy'] + _se[bad_soilXY`yy']*invttail(e(N),0.05)
mat treat[`pos',4] = _b[bad_soilXY`yy'] - _se[bad_soilXY`yy']*invttail(e(N),0.05)
}

g yy = treat[_n,1] in 1/55
g eff = treat[_n,2] in 1/55
g eff_10 = treat[_n,3] in 1/55
g eff_90 = treat[_n,4] in 1/55

label var eff "Coefficient"
label var eff_10 "Lower bound CI 10"
label var eff_90 "Higher bound CI 90"
label var tetra_corr "Lead (19 years lag)"

sort year

drop if year<1960

twoway (rcap eff_10 eff_90 yy, yaxis(1) ytitle("Coefficient") lc(black)) (scatter eff yy, mc(black) ylabel(-1(1)5) yaxis(1) xlabel(1960(5)2015) xtitle("Year") ) (line tetra_corr year, yaxis(2) lc(gs10))

